package com.xxx.reggie.mapper;

import com.xxx.reggie.dto.DishDto;
import com.xxx.reggie.entity.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DishMapper {

    @Select("select count(*) from dish where category_id=#{cid}")
    Integer findByCid(long cid);


    //插入一个菜品到数据库
    //添加菜品,并且获取到添加后的主键
    @Insert("INSERT INTO dish " +
            "VALUES(NULL,#{name},#{categoryId},#{price},#{code}," +
            "#{image},#{description},#{status},#{sort},#{createTime}," +
            "#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer save(DishDto dishDto);

    //查询所有菜品数据
    @Select("SELECT d.*,c.name  category_name FROM dish d INNER JOIN category c ON d.category_id = c.id ")
    List<DishDto> findByPage();


    //根据菜品id查询一个菜品和对应多条口味记录数据
    DishDto findById(long id);

    //根据id修改菜品
    void updateById(DishDto dishDto);

    //根据类别id查询菜品列表的方法
    @Select("select * from dish where category_id=#{cid} and status=#{status}")
    List<Dish> findAllByCid(@Param("cid") Long cid,@Param("status") Integer status);


    //2022年2月11日15:29:24

    //根据id批量删除菜品
    Integer deleteById(@Param("ids")List<Long> ids);

    //根据菜品id，查询状态为1的总数.
    Long selectByStatus(@Param("ids") List<Long> ids);


    //批量启售菜品,查询是否为起售状态.
    Integer findByDishId(@Param("ids")List<Long> ids,@Param("status") Integer status);

}
